<?php
namespace App\Http\Controllers\Admin\MicroBlog;

use App\Response\Response;
use Illuminate\Http\Request;    //引用http请求类
use \App\Http\Controllers\BaseController;
use App\Exceptions\BasicException;

class MicroBlogController extends BaseController
{
    /**
     * @api {get} /microblog/waitMachineCheckList 待机器审核列表
     * @apiGroup 补充接口-动态管理
     *
     * @apiParam {int} user_code 用户ID  非必传
     * @apiParam {int} page 页码  非必传（默认为1）
     * @apiParam {int} per_page 分页尺寸  非必传（默认为20）
     *
     * @apiError 10010 参数校验错误
     *
     * @apiSuccessExample 成功响应
     *
    {
    "code": 200,
    "data": {
    "total 记录总数": 272,
    "current_page 当前页码数": 1,
    "last_page_number 最后一页页码数": 14,
    "list": [{
    "id 序号": 3,
    "cover 封面图": "",
    "content 内容": "订单",
    "img_arr 资源列表": [{
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/5C12A60D-FA64-4A23-8FA8-C1617111567E.jpeg",
    "width": 828,
    "height": 828
    }, {
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/E2796D9B-066D-44DB-8DA1-71E940A88A53.jpeg",
    "width": 744,
    "height": 1322
    }, {
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/E8B22074-755E-4AC8-AAE3-0B550CDAA274.jpeg",
    "width": 750,
    "height": 1334
    }],
    "add_time": "01-20 18:11",
    "verify 审核状态 1：待机器审核 2：机器审核完毕待人工审核 3： 人工审核成功 4：人工审核失败": 1,
    "type 资源类型 1：图片，2：视频": 1,
    "nickname 昵称": "没有恩怨啊",
    "head_picture 头像": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }, {
    "id": 4,
    "cover": "",
    "content": "你在我",
    "img_arr": null,
    "add_time": "01-20 18:11",
    "verify": 1,
    "type": 1,
    "nickname": "没有恩怨啊",
    "head_picture": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }, {
    "id": 5,
    "cover": "",
    "content": "ｕ嘟嘟记得带回家了",
    "img_arr": null,
    "add_time": "01-20 18:12",
    "verify": 1,
    "type": 1,
    "nickname": "没有恩怨啊",
    "head_picture": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }]
    }
    }
     *
     */
    public function waitMachineCheckList(Request $request)
    {
        $v = app('validator')->make($request->all(),
            [
                'page' => 'filled|integer|gt:0',
                'per_page' => 'filled|integer|gt:0',
                'user_code' => 'filled|integer|gt:0'
            ]
        );

        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $page = $request->input('page', 1);
        $perPage = $request->input('per_page', 20);
        $userCode = $request->input('user_code', 0);

        $result = app('repo_microblog')->list($page, $perPage, 1, $userCode);

        return Response::sendData($result);
    }

    /**
     * @api {get} /microblog/list 可人工审核动态列表
     * @apiVersion 0.1.0
     * @apiName 可人工审核动态列表
     * @apiGroup 动态管理
     *
     * @apiParam {int} user_code 用户ID  非必传
     * @apiParam {int} page 页码  非必传（默认为1）
     * @apiParam {int} per_page 分页尺寸  非必传（默认为20）
     *
     * @apiError 10010 参数校验错误
     *
     * @apiSuccessExample 成功响应
     *
    {
    "code": 200,
    "data": {
    "total 记录总数": 272,
    "current_page 当前页码数": 1,
    "last_page_number 最后一页页码数": 14,
    "list": [{
    "id 序号": 3,
    "cover 封面图": "",
    "content 内容": "订单",
    "img_arr 资源列表": [{
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/5C12A60D-FA64-4A23-8FA8-C1617111567E.jpeg",
    "width": 828,
    "height": 828
    }, {
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/E2796D9B-066D-44DB-8DA1-71E940A88A53.jpeg",
    "width": 744,
    "height": 1322
    }, {
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/E8B22074-755E-4AC8-AAE3-0B550CDAA274.jpeg",
    "width": 750,
    "height": 1334
    }],
    "add_time": "01-20 18:11",
    "verify 审核状态 1：待机器审核 2：机器审核完毕待人工审核 3： 人工审核成功 4：人工审核失败": 1,
    "type 资源类型 1：图片，2：视频": 1,
    "nickname 昵称": "没有恩怨啊",
    "head_picture 头像": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }, {
    "id": 4,
    "cover": "",
    "content": "你在我",
    "img_arr": null,
    "add_time": "01-20 18:11",
    "verify": 1,
    "type": 1,
    "nickname": "没有恩怨啊",
    "head_picture": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }, {
    "id": 5,
    "cover": "",
    "content": "ｕ嘟嘟记得带回家了",
    "img_arr": null,
    "add_time": "01-20 18:12",
    "verify": 1,
    "type": 1,
    "nickname": "没有恩怨啊",
    "head_picture": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }]
    }
    }
     *
     */
    public function list(Request $request)
    {
        $v = app('validator')->make($request->all(),
            [
                'page' => 'filled|integer|gt:0',
                'per_page' => 'filled|integer|gt:0',
                'user_code' => 'filled|integer|gt:0'
            ]
        );

        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $page = $request->input('page', 1);
        $perPage = $request->input('per_page', 20);
        $userCode = $request->input('user_code', 0);

        $result = app('repo_microblog')->list($page, $perPage, 2, $userCode);

        return Response::sendData($result);
    }

    /**
     * @api {get} /microblog/passList 人工审核成功列表
     * @apiVersion 0.1.0
     * @apiName 人工审核成功列表
     * @apiGroup 动态管理
     *
     * @apiParam {int} user_code 用户ID  非必传
     * @apiParam {int} page 页码  非必传（默认为1）
     * @apiParam {int} per_page 分页尺寸  非必传（默认为20）
     *
     * @apiError 10010 参数校验错误
     *
     * @apiSuccessExample 成功响应
     *
    {
    "code": 200,
    "data": {
    "total 记录总数": 272,
    "current_page 当前页码数": 1,
    "last_page_number 最后一页页码数": 14,
    "list": [{
    "id 序号": 3,
    "cover 封面图": "",
    "content 内容": "订单",
    "img_arr 资源列表": [{
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/5C12A60D-FA64-4A23-8FA8-C1617111567E.jpeg",
    "width": 828,
    "height": 828
    }, {
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/E2796D9B-066D-44DB-8DA1-71E940A88A53.jpeg",
    "width": 744,
    "height": 1322
    }, {
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/E8B22074-755E-4AC8-AAE3-0B550CDAA274.jpeg",
    "width": 750,
    "height": 1334
    }],
    "add_time": "01-20 18:11",
    "verify 审核状态 1：待机器审核 2：机器审核完毕待人工审核 3： 人工审核成功 4：人工审核失败": 1,
    "type 资源类型 1：图片，2：视频": 1,
    "nickname 昵称": "没有恩怨啊",
    "head_picture 头像": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }, {
    "id": 4,
    "cover": "",
    "content": "你在我",
    "img_arr": null,
    "add_time": "01-20 18:11",
    "verify": 1,
    "type": 1,
    "nickname": "没有恩怨啊",
    "head_picture": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }, {
    "id": 5,
    "cover": "",
    "content": "ｕ嘟嘟记得带回家了",
    "img_arr": null,
    "add_time": "01-20 18:12",
    "verify": 1,
    "type": 1,
    "nickname": "没有恩怨啊",
    "head_picture": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }]
    }
    }
     *
     */
    public function passList(Request $request)
    {
        $v = app('validator')->make($request->all(),
            [
                'page' => 'filled|integer|gt:0',
                'per_page' => 'filled|integer|gt:0',
                'user_code' => 'filled|integer|gt:0',
                'nickname' => '',
                'start_date' => 'date',
                'end_date'   => 'date',
            ]
        );

        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $page = $request->input('page', 1);
        $perPage = $request->input('per_page', 20);
        $userCode = $request->input('user_code', 0);
        $params = $request->all();


        $result = app('repo_microblog')->listPassed($page, $perPage, 3, $userCode,$params);

        return Response::sendData($result);
    }

    /**
     * @api {get} /microblog/refuseList 人工审核拒绝列表
     * @apiVersion 0.1.0
     * @apiName 人工审核拒绝列表
     * @apiGroup 动态管理
     *
     * @apiParam {int} user_code 用户ID  非必传
     * @apiParam {int} page 页码  非必传（默认为1）
     * @apiParam {int} per_page 分页尺寸  非必传（默认为20）
     *
     * @apiError 10010 参数校验错误
     *
     * @apiSuccessExample 成功响应
     *
    {
    "code": 200,
    "data": {
    "total 记录总数": 272,
    "current_page 当前页码数": 1,
    "last_page_number 最后一页页码数": 14,
    "list": [{
    "id 序号": 3,
    "cover 封面图": "",
    "content 内容": "订单",
    "img_arr 资源列表": [{
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/5C12A60D-FA64-4A23-8FA8-C1617111567E.jpeg",
    "width": 828,
    "height": 828
    }, {
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/E2796D9B-066D-44DB-8DA1-71E940A88A53.jpeg",
    "width": 744,
    "height": 1322
    }, {
    "url": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/ios_images\/2021-01-20\/E8B22074-755E-4AC8-AAE3-0B550CDAA274.jpeg",
    "width": 750,
    "height": 1334
    }],
    "add_time": "01-20 18:11",
    "verify 审核状态 1：待机器审核 2：机器审核完毕待人工审核 3： 人工审核成功 4：人工审核失败": 1,
    "type 资源类型 1：图片，2：视频": 1,
    "nickname 昵称": "没有恩怨啊",
    "head_picture 头像": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }, {
    "id": 4,
    "cover": "",
    "content": "你在我",
    "img_arr": null,
    "add_time": "01-20 18:11",
    "verify": 1,
    "type": 1,
    "nickname": "没有恩怨啊",
    "head_picture": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }, {
    "id": 5,
    "cover": "",
    "content": "ｕ嘟嘟记得带回家了",
    "img_arr": null,
    "add_time": "01-20 18:12",
    "verify": 1,
    "type": 1,
    "nickname": "没有恩怨啊",
    "head_picture": "https:\/\/yutangyuyin.oss-cn-hangzhou.aliyuncs.com\/custom\/default_avatar.png"
    }]
    }
    }
     *
     */
    public function refuseList(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                'page' => 'filled|integer|gt:0',
                'per_page' => 'filled|integer|gt:0',
                'user_code' => 'filled|integer|gt:0'
            ]
        );

        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $page = $request->input('page', 1);
        $perPage = $request->input('per_page', 20);
        $userCode = $request->input('user_code', 0);

        $result = app('repo_microblog')->list($page, $perPage, 4, $userCode);

        return Response::sendData($result);
    }

    /**
     * @api {post} /microblog/audit 审核
     * @apiVersion 0.1.0
     * @apiName 人工审核通过接口
     * @apiGroup 动态管理
     *
     * @apiParam {string} ids 记录ID  必传，多个用英文下逗号连接
     * @apiParam {string} audit_res 审核结果，必传：1：审核通过；0：审核拒绝
     *
     * @apiError 10010 参数校验错误
     *
     * @apiSuccessExample 成功响应
     *
    {
    "code": 200,
    "data": []
    }
     *
     */
    public function audit(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                'ids' => 'required',
                'audit_res' => 'required|integer|in:1,0',
            ],
            [
                'ids.required' => '请选择要审核的记录',
                'audit_res.required' => '参数错误',
                'audit_res.integer' => '参数错误',
                'audit_res.in' => '参数错误',
            ]
        );
        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $ids = $request->input('ids');
        $auditRes = $request->input('audit_res');
        $auditRes = $auditRes == 1 ? 3 : 4;
        $result = app('repo_microblog')->check($ids, $auditRes);

        return Response::sendData([]);
    }

    /**
     * @api {post} /microblog/delete 删除
     * @apiVersion 0.1.0
     * @apiName 删除接口
     * @apiGroup 动态管理
     *
     * @apiParam {int} id 记录ID  必传
     *
     * @apiError 10010 参数校验错误
     *
     * @apiSuccessExample 成功响应
     *
    {
    "code": 200,
    "data": []
    }
     *
     */
    public function delete(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => 'required|numeric|gt:0'
            ]
        );

        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $id = $request->input('id');
        $result = app('repo_microblog')->delete($id);

        return Response::sendData($result);
    }

    /**
     * Notes:删除评论
     * User: wangyueli
     *
     * @param  Request  $request
     * @return string
     * @throws BasicException
     */
    public function deleteComment(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                'id' => 'required',
            ]
        );
        if ($v->fails()) {
            throw new BasicException(10001, getValidateMessage($v->messages()));
        }

        $id = $request->input('id');

        $result = app('repo_microblog')->deleteComment($id);

        return Response::sendData(true);
    }

    /**
     * Notes:获取评论列表
     * User: wangyueli
     *
     * @param  Request  $request
     * @return string
     * @throws BasicException
     */
    public function getCommentList(Request $request)
    {
        $v = app('validator')->make($request->all(),
            [
                'page' => 'filled|integer|gt:0',
                'per_page' => 'filled|integer|gt:0',
                'id' => 'required|numeric|gt:0'
            ]
        );

        if ($v->fails()) throw new BasicException(10001, getValidateMessage($v->messages()));

        $page = $request->input('page', 1);
        $perPage = $request->input('per_page', 20);
        $blog_id = $request->input('id', 0);

        $result = app('repo_microblog')->getCommentList($page, $perPage,$blog_id);

        return Response::sendData($result);
    }
}
